package extendS;

import java.util.Arrays;
import java.util.Comparator;

class Student {
    private String name;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
class ScoreComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return (int)(o1.score- o2.score);
    }
}
public class Demo6 {
    public static void main(String[] args) {
        Student stu1=new Student("王1",19,82.5);
        Student stu2=new Student("王2",15,22.5);
        Student stu3=new Student("王3",25,42.5);
        Student[] student={stu1,stu2,stu3};
        //传入比较器按照分数排序
        System.out.println("排序前数组");
        System.out.println(Arrays.toString(student));
        Arrays.sort(student,new ScoreComparator());
        System.out.println("用分数比较器排序好的数组");
        System.out.println(Arrays.toString(student));


    }
}
